*! version 3.0 13Mar2017 

*! Modified from icd9_ff.ado by HJW

program define hjw_ff, rclass
   version 6
   gettoken fn 0 : 0, parse(" ,")
   syntax [, ADO]

   global ifn = 0

   local sep : dirsep
   local ltr = substr(`"`fn'"',1,1)
   if `"`ltr'"' != "" {
     tokenize `"$S_ADO"', parse(" ;")
      while `"`1'"' != "" {
         if `"`1'"' != ";" {

                 *! hjw modify
                 if `"`1'"' == "." {
                  local 1 : pwd
                 }
                 *! hjw modify end

            local realdir : sysdir `"`1'"'
            return local fn `"`realdir'`fn'"'
            capture confirm file `"`return(fn)'"'
            if _rc==0 {

global ifn = $ifn + 1
global fn$ifn `"`return(fn)'"'

*               di in gr `"`return(fn)'"'
*               exit
            }
            return local fn `"`realdir'`ltr'`sep'`fn'"'
            capture confirm file `"`return(fn)'"'
            if _rc==0 { /* file exist */
global ifn = $ifn + 1
global fn$ifn `"`realdir'`ltr'`sep'`fn'"'

*               di in gr `"`return(fn)'"'
*               exit
            }
         }
         mac shift
      }
   }
   if $ifn == 0 {
   di in red `"file "`fn'" not found"'
   exit 601
   }
end
